package com.dux.shiro1.web.error;

/**
 * Title: RBody <br>
 * Description: RBody <br>
 * Date: 2018年10月22日
 *
 * @author 王东旭
 * @version 1.0.0
 * @since jdk8
 */
public class RBody {

    /**
     * 错误代码
     */
    private String code;
    /**
     * 错误信息
     */
    private String msg;

    /**
     * 错误附带的数据
     */
    private Object data;

    public RBody(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public RBody(CodeEnum codeEnum){
        this(codeEnum.getCode(),codeEnum.getMsg(),null);
    }

    public RBody(CodeEnum codeEnum,Object data){
        this(codeEnum.getCode(),codeEnum.getMsg(),null);
    }

    public static RBody ok(){
        return new RBody(CodeEnum.SUCCESS);
    }

    public static RBody error(){
        return new RBody(CodeEnum.SYSTEM_ERROR);
    }
    public static RBody error(CodeEnum codeEnum){
        return new RBody(codeEnum);
    }
    public static RBody error(String msg,CodeEnum codeEnum){
        return new RBody(codeEnum.getCode(),msg,null);
    }

    public static RBody error(String msg,CodeEnum codeEnum,String data){
        return new RBody(codeEnum.getCode(),msg,data);
    }

    public RBody() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "RBody{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
